

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>pysimm.forcefield.gaff &mdash; pysimm 0.2 documentation</title>
  

  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  

  

  
    <link rel="top" title="pysimm 0.2 documentation" href="../../../index.html"/>
        <link rel="up" title="pysimm" href="../../pysimm.html"/> 

  
  <script src="../../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../../index.html" class="icon icon-home"> pysimm
          

          
          </a>

          
            
            
              <div class="version">
                0.2
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
                <ul>
<li class="toctree-l1"><a class="reference internal" href="../../../pysimm.html">pysimm package</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="../../../index.html">pysimm</a>
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          





<div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="../../../index.html">Docs</a> &raquo;</li>
      
          <li><a href="../../index.html">Module code</a> &raquo;</li>
      
          <li><a href="../../pysimm.html">pysimm</a> &raquo;</li>
      
    <li>pysimm.forcefield.gaff</li>
      <li class="wy-breadcrumbs-aside">
        
          
        
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for pysimm.forcefield.gaff</h1><div class="highlight"><pre>
<span></span><span class="c1"># ******************************************************************************</span>
<span class="c1"># pysimm.forcefield.gaff module</span>
<span class="c1"># ******************************************************************************</span>
<span class="c1">#</span>
<span class="c1"># ******************************************************************************</span>
<span class="c1"># License</span>
<span class="c1"># ******************************************************************************</span>
<span class="c1"># The MIT License (MIT)</span>
<span class="c1">#</span>
<span class="c1"># Copyright (c) 2016 Michael E. Fortunato, Coray M. Colina</span>
<span class="c1">#</span>
<span class="c1"># Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<span class="c1"># of this software and associated documentation files (the &quot;Software&quot;), to deal</span>
<span class="c1"># in the Software without restriction, including without limitation the rights</span>
<span class="c1"># to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span>
<span class="c1"># copies of the Software, and to permit persons to whom the Software is</span>
<span class="c1"># furnished to do so, subject to the following conditions:</span>
<span class="c1">#</span>
<span class="c1"># The above copyright notice and this permission notice shall be included in</span>
<span class="c1"># all copies or substantial portions of the Software.</span>
<span class="c1">#</span>
<span class="c1"># THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<span class="c1"># IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<span class="c1"># FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<span class="c1"># AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<span class="c1"># LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<span class="c1"># OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN</span>
<span class="c1"># THE SOFTWARE.</span>

<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">permutations</span><span class="p">,</span> <span class="n">combinations</span>

<span class="kn">import</span> <span class="nn">gasteiger</span>
<span class="kn">from</span> <span class="nn">pysimm.system</span> <span class="kn">import</span> <span class="n">Angle</span><span class="p">,</span> <span class="n">Dihedral</span><span class="p">,</span> <span class="n">Improper</span>
<span class="kn">from</span> <span class="nn">forcefield</span> <span class="kn">import</span> <span class="n">Forcefield</span>


<div class="viewcode-block" id="Gaff"><a class="viewcode-back" href="../../../pysimm.forcefield.gaff.html#pysimm.forcefield.gaff.Gaff">[docs]</a><span class="k">class</span> <span class="nc">Gaff</span><span class="p">(</span><span class="n">Forcefield</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.forcefield.Gaff</span>

<span class="sd">    Forcefield object with typing rules for Gaff model.</span>
<span class="sd">    By default reads data file in forcefields subdirectory.</span>

<span class="sd">    Attributes:</span>
<span class="sd">        ff_name: gaff</span>
<span class="sd">        pair_style: lj</span>
<span class="sd">        ff_class: 1</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">db_file</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">db_file</span> <span class="ow">and</span> <span class="n">db_file</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">False</span><span class="p">:</span>
            <span class="n">db_file</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">realpath</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)),</span>
                                   <span class="n">os</span><span class="o">.</span><span class="n">pardir</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">pardir</span><span class="p">,</span> <span class="s1">&#39;dat&#39;</span><span class="p">,</span> <span class="s1">&#39;forcefields&#39;</span><span class="p">,</span> <span class="s1">&#39;gaff.json&#39;</span><span class="p">)</span>
        <span class="n">Forcefield</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">db_file</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;gaff&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">pair_style</span> <span class="o">=</span> <span class="s1">&#39;lj&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bond_style</span> <span class="o">=</span> <span class="s1">&#39;harmonic&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">angle_style</span> <span class="o">=</span> <span class="s1">&#39;harmonic&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_style</span> <span class="o">=</span> <span class="s1">&#39;fourier&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">improper_style</span> <span class="o">=</span> <span class="s1">&#39;cvff&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">=</span> <span class="s1">&#39;1&#39;</span>

<div class="viewcode-block" id="Gaff.assign_ptypes"><a class="viewcode-back" href="../../../pysimm.forcefield.gaff.html#pysimm.forcefield.gaff.Gaff.assign_ptypes">[docs]</a>    <span class="k">def</span> <span class="nf">assign_ptypes</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">s</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.forcefield.Gaff.assign_ptypes</span>

<span class="sd">        Gaff specific particle typing rules.</span>
<span class="sd">        Requires :class:`~pysimm.system.System` object :class:`~pysimm.system.Particle` objects have bonds defined.</span>
<span class="sd">        *** use System.add_particle_bonding() to ensure this ***</span>

<span class="sd">        *** Not entirely inclusive - some atom types not used ***</span>

<span class="sd">        Args:</span>
<span class="sd">            s: :class:`~pysimm.system.System`</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">all_types</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
        <span class="n">s</span><span class="o">.</span><span class="n">pair_style</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pair_style</span>
        <span class="n">s</span><span class="o">.</span><span class="n">add_particle_bonding</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">bond_orders</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">order</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bonds</span><span class="p">]</span>
            <span class="k">if</span> <span class="bp">None</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_orders</span><span class="p">:</span>
                <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;error: bond orders are not set&#39;</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">elem</span> <span class="k">if</span> <span class="n">p</span> <span class="ow">is</span> <span class="n">x</span><span class="o">.</span><span class="n">b</span> <span class="k">else</span> <span class="n">x</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">elem</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span>
                               <span class="n">p</span><span class="o">.</span><span class="n">bonds</span><span class="p">]</span>
            <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">linker</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;H&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="s1">&#39;O&#39;</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span><span class="p">:</span>
                    <span class="n">water</span> <span class="o">=</span> <span class="bp">False</span>
                    <span class="k">for</span> <span class="n">pb</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">pb</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;O&#39;</span> <span class="ow">and</span> <span class="n">pb</span><span class="o">.</span><span class="n">bond_elements</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s1">&#39;H&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                            <span class="n">water</span> <span class="o">=</span> <span class="bp">True</span>
                    <span class="k">if</span> <span class="n">water</span><span class="p">:</span>
                        <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;hw&#39;</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;ho&#39;</span>
                <span class="k">elif</span> <span class="s1">&#39;N&#39;</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;hn&#39;</span>
                <span class="k">elif</span> <span class="s1">&#39;P&#39;</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;hp&#39;</span>
                <span class="k">elif</span> <span class="s1">&#39;S&#39;</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;hs&#39;</span>
                <span class="k">elif</span> <span class="s1">&#39;C&#39;</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">pb</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">pb</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;C&#39;</span><span class="p">:</span>
                            <span class="n">elctrwd</span> <span class="o">=</span> <span class="p">(</span><span class="n">pb</span><span class="o">.</span><span class="n">bond_elements</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s1">&#39;N&#39;</span><span class="p">)</span> <span class="o">+</span>
                                       <span class="n">pb</span><span class="o">.</span><span class="n">bond_elements</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s1">&#39;O&#39;</span><span class="p">)</span> <span class="o">+</span>
                                       <span class="n">pb</span><span class="o">.</span><span class="n">bond_elements</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s1">&#39;F&#39;</span><span class="p">)</span> <span class="o">+</span>
                                       <span class="n">pb</span><span class="o">.</span><span class="n">bond_elements</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s1">&#39;P&#39;</span><span class="p">)</span> <span class="o">+</span>
                                       <span class="n">pb</span><span class="o">.</span><span class="n">bond_elements</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s1">&#39;S&#39;</span><span class="p">)</span> <span class="o">+</span>
                                       <span class="n">pb</span><span class="o">.</span><span class="n">bond_elements</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s1">&#39;Cl&#39;</span><span class="p">))</span>
                            <span class="k">if</span> <span class="mi">4</span> <span class="ow">in</span> <span class="n">pb</span><span class="o">.</span><span class="n">bond_orders</span> <span class="ow">or</span> <span class="s1">&#39;A&#39;</span> <span class="ow">in</span> <span class="n">pb</span><span class="o">.</span><span class="n">bond_orders</span><span class="p">:</span>
                                <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;ha&#39;</span>
                            <span class="k">elif</span> <span class="n">elctrwd</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                                <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;hc&#39;</span>
                            <span class="k">elif</span> <span class="n">pb</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">4</span> <span class="ow">and</span> <span class="n">elctrwd</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                                <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;h1&#39;</span>
                            <span class="k">elif</span> <span class="n">pb</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">4</span> <span class="ow">and</span> <span class="n">elctrwd</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                                <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;h2&#39;</span>
                            <span class="k">elif</span> <span class="n">pb</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">4</span> <span class="ow">and</span> <span class="n">elctrwd</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                                <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;h3&#39;</span>
                            <span class="k">elif</span> <span class="n">pb</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">3</span> <span class="ow">and</span> <span class="n">elctrwd</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                                <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;h4&#39;</span>
                            <span class="k">elif</span> <span class="n">pb</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">3</span> <span class="ow">and</span> <span class="n">elctrwd</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                                <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;h5&#39;</span>
            <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;C&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">3</span> <span class="ow">and</span> <span class="s1">&#39;O&#39;</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;c&#39;</span>
                <span class="k">elif</span> <span class="mi">4</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_orders</span> <span class="ow">or</span> <span class="s1">&#39;A&#39;</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_orders</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">pb</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">pb</span><span class="o">.</span><span class="n">elem</span> <span class="o">!=</span> <span class="s1">&#39;C&#39;</span> <span class="ow">and</span> <span class="n">pb</span><span class="o">.</span><span class="n">elem</span> <span class="o">!=</span> <span class="s1">&#39;H&#39;</span><span class="p">:</span>
                            <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;cc&#39;</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">p</span><span class="o">.</span><span class="n">type_name</span><span class="p">:</span>
                        <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;ca&#39;</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;c3&#39;</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">3</span> <span class="ow">and</span> <span class="ow">not</span> <span class="s1">&#39;O&#39;</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span><span class="p">:</span>
                        <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;c2&#39;</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;c1&#39;</span>
            <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;F&#39;</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;f&#39;</span>
            <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;Cl&#39;</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;cl&#39;</span>
            <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;Br&#39;</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;br&#39;</span>
            <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;I&#39;</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;i&#39;</span>
            <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;N&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="mi">2</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_orders</span> <span class="ow">and</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;n2&#39;</span>
                <span class="k">elif</span> <span class="mi">2</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_orders</span> <span class="ow">and</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;na&#39;</span>
                <span class="k">elif</span> <span class="mi">3</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_orders</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;n1&#39;</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s1">&#39;O&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;no&#39;</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">&lt;=</span> <span class="mi">3</span><span class="p">:</span>
                    <span class="n">amide</span> <span class="o">=</span> <span class="bp">False</span>
                    <span class="n">aromatic_ring</span> <span class="o">=</span> <span class="bp">False</span>
                    <span class="k">for</span> <span class="n">pb</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">pb</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;C&#39;</span><span class="p">:</span>
                            <span class="k">if</span> <span class="mi">4</span> <span class="ow">in</span> <span class="n">pb</span><span class="o">.</span><span class="n">bond_orders</span> <span class="ow">or</span> <span class="s1">&#39;A&#39;</span> <span class="ow">in</span> <span class="n">pb</span><span class="o">.</span><span class="n">bond_orders</span><span class="p">:</span>
                                <span class="n">aromatic_ring</span> <span class="o">=</span> <span class="bp">True</span>
                            <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">pb</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
                                <span class="n">bp</span> <span class="o">=</span> <span class="n">b</span><span class="o">.</span><span class="n">a</span> <span class="k">if</span> <span class="n">pb</span> <span class="ow">is</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span> <span class="k">else</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span>
                                <span class="k">if</span> <span class="n">bp</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;O&#39;</span> <span class="ow">and</span> <span class="n">b</span><span class="o">.</span><span class="n">order</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                                    <span class="n">amide</span> <span class="o">=</span> <span class="bp">True</span>
                    <span class="k">if</span> <span class="n">amide</span><span class="p">:</span>
                        <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;n&#39;</span>
                    <span class="k">elif</span> <span class="p">(</span><span class="mi">4</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_orders</span> <span class="ow">or</span> <span class="s1">&#39;A&#39;</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_orders</span><span class="p">)</span> <span class="ow">and</span> <span class="s1">&#39;C&#39;</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span><span class="p">:</span>
                        <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;nc&#39;</span>
                    <span class="k">elif</span> <span class="n">aromatic_ring</span><span class="p">:</span>
                        <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;nh&#39;</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;n3&#39;</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;n4&#39;</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">print</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">elem</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_orders</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;O&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;o&#39;</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s1">&#39;H&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;ow&#39;</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s1">&#39;H&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;oh&#39;</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;os&#39;</span>
            <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;P&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="mi">4</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_orders</span> <span class="ow">or</span> <span class="s1">&#39;A&#39;</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_orders</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;pc&#39;</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;p2&#39;</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">3</span> <span class="ow">and</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s1">&#39;H&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;p3&#39;</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;p4&#39;</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;p5&#39;</span>
            <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span> <span class="o">==</span> <span class="s1">&#39;S&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;s&#39;</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">2</span> <span class="ow">and</span> <span class="mi">2</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_orders</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;s2&#39;</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;s4&#39;</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;s6&#39;</span>
                <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">bond_orders</span><span class="p">))</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_orders</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="k">if</span> <span class="s1">&#39;H&#39;</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bond_elements</span><span class="p">:</span>
                        <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;sh&#39;</span>
                    <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">nbonds</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                        <span class="n">p</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="s1">&#39;ss&#39;</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">print</span> <span class="s1">&#39;cant type particle </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">p</span><span class="o">.</span><span class="n">tag</span>
                <span class="k">return</span> <span class="n">p</span>

            <span class="n">type_</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">type_name</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">type_</span><span class="p">:</span>
                <span class="k">print</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">elem</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">type_name</span><span class="p">)</span>

            <span class="n">all_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">type_name</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>

        <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="n">all_types</span><span class="p">:</span>
            <span class="n">pt</span> <span class="o">=</span> <span class="n">pt</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
            <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">pt</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="n">pt</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">particle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">type_name</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">pt</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">pt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></div>

<div class="viewcode-block" id="Gaff.assign_btypes"><a class="viewcode-back" href="../../../pysimm.forcefield.gaff.html#pysimm.forcefield.gaff.Gaff.assign_btypes">[docs]</a>    <span class="k">def</span> <span class="nf">assign_btypes</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">s</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.forcefield.Gaff.assign_btypes</span>

<span class="sd">        Gaff specific bond typing rules.</span>
<span class="sd">        Requires :class:`~pysimm.system.System` object :class:`~pysimm.system.Particle` objects have bonds, type and type.name defined.</span>
<span class="sd">        *** use after assign_ptypes ***</span>

<span class="sd">        Args:</span>
<span class="sd">            s: :class:`~pysimm.system.System`</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">all_types</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
        <span class="n">s</span><span class="o">.</span><span class="n">bond_style</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_style</span>
        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
            <span class="n">bt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
            <span class="k">if</span> <span class="n">bt</span><span class="p">:</span>
                <span class="n">b</span><span class="o">.</span><span class="n">type_name</span> <span class="o">=</span> <span class="n">bt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">name</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">print</span> <span class="p">(</span><span class="s1">&#39;couldnt type this bond </span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">&#39;</span>
                       <span class="o">%</span> <span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
                <span class="k">return</span> <span class="n">b</span>
            <span class="n">all_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">type_name</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>

        <span class="k">for</span> <span class="n">bt</span> <span class="ow">in</span> <span class="n">all_types</span><span class="p">:</span>
            <span class="n">bt</span> <span class="o">=</span> <span class="n">bt</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
            <span class="n">s</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">bt</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
            <span class="n">bt</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">bond_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">type_name</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">bt</span><span class="p">:</span>
                <span class="n">b</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">bt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></div>

<div class="viewcode-block" id="Gaff.assign_atypes"><a class="viewcode-back" href="../../../pysimm.forcefield.gaff.html#pysimm.forcefield.gaff.Gaff.assign_atypes">[docs]</a>    <span class="k">def</span> <span class="nf">assign_atypes</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">s</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.forcefield.Gaff.assign_atypes</span>

<span class="sd">        Gaff specific boanglend typing rules.</span>
<span class="sd">        Requires :class:`~pysimm.system.System` object :class:`~pysimm.system.Particle` objects have bonds, type and type.name defined.</span>
<span class="sd">        *** use after assign_ptypes ***</span>

<span class="sd">        Args:</span>
<span class="sd">            s: :class:`~pysimm.system.System`</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">all_types</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
        <span class="n">s</span><span class="o">.</span><span class="n">angle_style</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_style</span>
        <span class="n">s</span><span class="o">.</span><span class="n">add_particle_bonding</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">p1</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">p2</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">p1</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">p2</span><span class="p">:</span>
                        <span class="n">unique</span> <span class="o">=</span> <span class="bp">True</span>
                        <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">angles</span><span class="p">:</span>
                            <span class="k">if</span> <span class="p">((</span><span class="n">a</span><span class="o">.</span><span class="n">a</span> <span class="ow">is</span> <span class="n">p1</span> <span class="ow">and</span> <span class="n">a</span><span class="o">.</span><span class="n">b</span> <span class="ow">is</span> <span class="n">p</span> <span class="ow">and</span> <span class="n">a</span><span class="o">.</span><span class="n">c</span> <span class="ow">is</span> <span class="n">p2</span><span class="p">)</span> <span class="ow">or</span>
                                    <span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">a</span> <span class="ow">is</span> <span class="n">p2</span> <span class="ow">and</span> <span class="n">a</span><span class="o">.</span><span class="n">b</span> <span class="ow">is</span> <span class="n">p</span> <span class="ow">and</span> <span class="n">a</span><span class="o">.</span><span class="n">c</span> <span class="ow">is</span> <span class="n">p1</span><span class="p">)):</span>
                                <span class="n">unique</span> <span class="o">=</span> <span class="bp">False</span>
                        <span class="k">if</span> <span class="n">unique</span><span class="p">:</span>
                            <span class="n">at</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">&#39;</span>
                                                      <span class="o">%</span> <span class="p">(</span><span class="n">p1</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                                                         <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                                                         <span class="n">p2</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
                            <span class="k">if</span> <span class="n">at</span><span class="p">:</span>
                                <span class="n">s</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Angle</span><span class="p">(</span><span class="n">type_name</span><span class="o">=</span><span class="n">at</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                                                   <span class="n">a</span><span class="o">=</span><span class="n">p1</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">p</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="n">p2</span><span class="p">))</span>
                                <span class="n">all_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">at</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                            <span class="k">else</span><span class="p">:</span>
                                <span class="k">print</span> <span class="p">(</span><span class="s1">&#39;I cant type this angle </span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">&#39;</span>
                                       <span class="o">%</span> <span class="p">(</span><span class="n">p1</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                                          <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                                          <span class="n">p2</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>

        <span class="k">for</span> <span class="n">at</span> <span class="ow">in</span> <span class="n">all_types</span><span class="p">:</span>
            <span class="n">at</span> <span class="o">=</span> <span class="n">at</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
            <span class="n">s</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">at</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">angles</span><span class="p">:</span>
            <span class="n">at</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">angle_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">type_name</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">at</span><span class="p">:</span>
                <span class="n">a</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">at</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></div>

<div class="viewcode-block" id="Gaff.assign_dtypes"><a class="viewcode-back" href="../../../pysimm.forcefield.gaff.html#pysimm.forcefield.gaff.Gaff.assign_dtypes">[docs]</a>    <span class="k">def</span> <span class="nf">assign_dtypes</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">s</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.forcefield.Gaff.assign_dtypes</span>

<span class="sd">        Gaff specific dihedral typing rules.</span>
<span class="sd">        Requires :class:`~pysimm.system.System` object :class:`~pysimm.system.Particle` objects have bonds, type and type.name defined.</span>
<span class="sd">        *** use after assign_ptypes ***</span>

<span class="sd">        Args:</span>
<span class="sd">            s: :class:`~pysimm.system.System`</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">all_types</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
        <span class="n">s</span><span class="o">.</span><span class="n">dihedral_style</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_style</span>
        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">p1</span> <span class="ow">in</span> <span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">p2</span> <span class="ow">in</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">p1</span> <span class="ow">is</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span> <span class="ow">or</span> <span class="n">p2</span> <span class="ow">is</span> <span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="p">:</span>
                        <span class="k">continue</span>
                    <span class="n">unique</span> <span class="o">=</span> <span class="bp">True</span>
                    <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">:</span>
                        <span class="k">if</span> <span class="p">((</span><span class="n">d</span><span class="o">.</span><span class="n">a</span> <span class="o">==</span> <span class="n">p1</span> <span class="ow">and</span> <span class="n">d</span><span class="o">.</span><span class="n">b</span> <span class="o">==</span> <span class="n">b</span><span class="o">.</span><span class="n">a</span> <span class="ow">and</span>
                                <span class="n">d</span><span class="o">.</span><span class="n">c</span> <span class="o">==</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span> <span class="ow">and</span> <span class="n">d</span><span class="o">.</span><span class="n">d</span> <span class="o">==</span> <span class="n">p2</span><span class="p">)</span> <span class="ow">or</span>
                            <span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">a</span> <span class="o">==</span> <span class="n">p2</span> <span class="ow">and</span> <span class="n">d</span><span class="o">.</span><span class="n">b</span> <span class="o">==</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span> <span class="ow">and</span>
                                <span class="n">d</span><span class="o">.</span><span class="n">c</span> <span class="o">==</span> <span class="n">b</span><span class="o">.</span><span class="n">a</span> <span class="ow">and</span> <span class="n">d</span><span class="o">.</span><span class="n">d</span> <span class="o">==</span> <span class="n">p1</span><span class="p">)):</span>
                            <span class="n">unique</span> <span class="o">=</span> <span class="bp">False</span>
                    <span class="k">if</span> <span class="n">unique</span><span class="p">:</span>
                        <span class="n">p1_name</span> <span class="o">=</span> <span class="n">p1</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
                        <span class="n">a_name</span> <span class="o">=</span> <span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
                        <span class="n">b_name</span> <span class="o">=</span> <span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
                        <span class="n">p2_name</span> <span class="o">=</span> <span class="n">p2</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
                        <span class="n">dt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">&#39;</span>
                                                     <span class="o">%</span> <span class="p">(</span><span class="n">p1_name</span><span class="p">,</span> <span class="n">a_name</span><span class="p">,</span>
                                                        <span class="n">b_name</span><span class="p">,</span> <span class="n">p2_name</span><span class="p">))</span>
                        <span class="k">if</span> <span class="n">dt</span><span class="p">:</span>
                            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">dt</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                                <span class="n">all_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">dt</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                                <span class="n">s</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Dihedral</span><span class="p">(</span><span class="n">type_name</span><span class="o">=</span><span class="n">dt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                                                         <span class="n">a</span><span class="o">=</span><span class="n">p1</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="p">,</span>
                                                         <span class="n">c</span><span class="o">=</span><span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="p">,</span> <span class="n">d</span><span class="o">=</span><span class="n">p2</span><span class="p">))</span>
                            <span class="k">else</span><span class="p">:</span>
                                <span class="n">index</span> <span class="o">=</span> <span class="mi">0</span>
                                <span class="n">x</span> <span class="o">=</span> <span class="mi">5</span>
                                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">dt</span><span class="p">)):</span>
                                    <span class="k">if</span> <span class="n">dt</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">x</span><span class="p">:</span>
                                        <span class="n">index</span> <span class="o">=</span> <span class="n">i</span>
                                        <span class="n">x</span> <span class="o">=</span> <span class="n">dt</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">)</span>
                                <span class="n">dt</span> <span class="o">=</span> <span class="n">dt</span><span class="p">[</span><span class="n">index</span><span class="p">]</span>
                                <span class="n">all_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">dt</span><span class="p">)</span>
                                <span class="n">s</span><span class="o">.</span><span class="n">dihedrals</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Dihedral</span><span class="p">(</span><span class="n">type_name</span><span class="o">=</span><span class="n">dt</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                                                         <span class="n">a</span><span class="o">=</span><span class="n">p1</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="p">,</span>
                                                         <span class="n">c</span><span class="o">=</span><span class="n">b</span><span class="o">.</span><span class="n">b</span><span class="p">,</span> <span class="n">d</span><span class="o">=</span><span class="n">p2</span><span class="p">))</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="k">print</span> <span class="p">(</span><span class="s1">&#39;I cant type this dihedral </span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">,</span><span class="si">%s</span><span class="s1">&#39;</span>
                                   <span class="o">%</span> <span class="p">(</span><span class="n">p1_name</span><span class="p">,</span> <span class="n">a_name</span><span class="p">,</span> <span class="n">b_name</span><span class="p">,</span> <span class="n">p2_name</span><span class="p">))</span>

        <span class="k">for</span> <span class="n">dt</span> <span class="ow">in</span> <span class="n">all_types</span><span class="p">:</span>
            <span class="n">dt</span> <span class="o">=</span> <span class="n">dt</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
            <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">dt</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">dihedrals</span><span class="p">:</span>
            <span class="n">dt</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">dihedral_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">type_name</span><span class="p">,</span> <span class="n">item_wildcard</span><span class="o">=</span><span class="bp">None</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">dt</span><span class="p">:</span>
                <span class="n">d</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">dt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></div>

<div class="viewcode-block" id="Gaff.assign_itypes"><a class="viewcode-back" href="../../../pysimm.forcefield.gaff.html#pysimm.forcefield.gaff.Gaff.assign_itypes">[docs]</a>    <span class="k">def</span> <span class="nf">assign_itypes</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">s</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.forcefield.Gaff.assign_itypes</span>

<span class="sd">        Gaff specific improper typing rules.</span>
<span class="sd">        There are none.</span>

<span class="sd">        Args:</span>
<span class="sd">            s: :class:`~pysimm.system.System`</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">all_types</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
        <span class="n">s</span><span class="o">.</span><span class="n">improper_style</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_style</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">perm</span> <span class="ow">in</span> <span class="n">permutations</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">bonded_to</span><span class="p">,</span> <span class="mi">3</span><span class="p">):</span>
                    <span class="n">p1_name</span> <span class="o">=</span> <span class="n">perm</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">eq_improper</span> <span class="ow">or</span> <span class="n">perm</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
                    <span class="n">p2_name</span> <span class="o">=</span> <span class="n">perm</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">eq_improper</span> <span class="ow">or</span> <span class="n">perm</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
                    <span class="n">p3_name</span> <span class="o">=</span> <span class="n">perm</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">eq_improper</span> <span class="ow">or</span> <span class="n">perm</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
                    <span class="n">it</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">p1_name</span><span class="p">,</span>
                                                           <span class="n">p2_name</span><span class="p">,</span> <span class="n">p3_name</span><span class="p">]),</span> <span class="n">order</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
                    <span class="k">if</span> <span class="n">it</span><span class="p">:</span>
                        <span class="n">all_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">it</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                        <span class="n">bonded_to</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">bonded_to</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;all&#39;</span><span class="p">)</span>
                        <span class="n">s</span><span class="o">.</span><span class="n">impropers</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">Improper</span><span class="p">(</span><span class="n">type_name</span><span class="o">=</span><span class="n">it</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                                                 <span class="n">a</span><span class="o">=</span><span class="n">p</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">bonded_to</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                                                 <span class="n">c</span><span class="o">=</span><span class="n">bonded_to</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                                                 <span class="n">d</span><span class="o">=</span><span class="n">bonded_to</span><span class="p">[</span><span class="mi">2</span><span class="p">]))</span>
                        <span class="k">break</span>

        <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="n">all_types</span><span class="p">:</span>
            <span class="n">it</span> <span class="o">=</span> <span class="n">it</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
            <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">it</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">impropers</span><span class="p">:</span>
            <span class="n">it</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">improper_types</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">type_name</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">it</span><span class="p">:</span>
                <span class="n">i</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">it</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></div>

<div class="viewcode-block" id="Gaff.assign_charges"><a class="viewcode-back" href="../../../pysimm.forcefield.gaff.html#pysimm.forcefield.gaff.Gaff.assign_charges">[docs]</a>    <span class="k">def</span> <span class="nf">assign_charges</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">charges</span><span class="o">=</span><span class="s1">&#39;gasteiger&#39;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.forcefield.Gaff.assign_charges</span>

<span class="sd">        Charge assignment. Gasteiger is default for now.</span>

<span class="sd">        Args:</span>
<span class="sd">            s: :class:`~pysimm.system.System`</span>
<span class="sd">            charges: gasteiger</span>

<span class="sd">        Returns:</span>
<span class="sd">            None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">charges</span> <span class="o">==</span> <span class="s1">&#39;gasteiger&#39;</span><span class="p">:</span>
            <span class="k">print</span><span class="p">(</span><span class="s1">&#39;adding gasteiger charges&#39;</span><span class="p">)</span>
            <span class="n">gasteiger</span><span class="o">.</span><span class="n">set_charges</span><span class="p">(</span><span class="n">s</span><span class="p">)</span></div></div>
</pre></div>

           </div>
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2017, https://pysimm.org.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../../../',
            VERSION:'0.2',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true
        };
    </script>
      <script type="text/javascript" src="../../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../../_static/doctools.js"></script>

  

  
  
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>